package com.lx.bbs;

import com.lx.bbs.controller.LoginInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.socket.server.standard.ServerEndpointExporter;

@SpringBootApplication
// 扫描接口
@MapperScan("com.lx.bbs.dao")
public class BbsBootApplication implements WebMvcConfigurer {

    public static void main(String[] args) {
        SpringApplication.run(BbsBootApplication.class, args);
    }



    @Value("${uploadDir}")
    String uploadDir;
    //添加静态资源映射
    //将本地文件映射到项目里面 addResourceLocations() 本机文件路径 addResourceHandler() 映射文件路径
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/image/head/**")
                // :file  外部文件路径
                .addResourceLocations(uploadDir);
        /*registry.addResourceHandler("/**")
                .addResourceLocations(
                        "file:D:/git store/ycdemo-3/bbs/src/main/webapp/"
//                        "file:/root/gitee/ycdemo-3/bbs/src/main/webapp/"

                );*/
    }



    // 配置拦截器
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new LoginInterceptor())
                .addPathPatterns("/post.html", "/back/**");
    }

    // 启用WebSocket支持
    @Bean
    public ServerEndpointExporter serverEndpointExporter() {
        return new ServerEndpointExporter();
    }



}
